package ml;

public abstract class LatchedRunnable implements Runnable {

	private final UpAndCountDownLatch latch;

	public LatchedRunnable(UpAndCountDownLatch latch) {
		this.latch = latch;
	}

	@Override
	public void run() {
		latch.countUp();
		try {
			latchedExec();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			latch.countDown();
		}
	}

	public abstract void latchedExec() throws Exception;
}
